home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Text / Edit / GoldED-Demo / installdata / golded / developer / scanner / examples / html / html.c
Encoding:
C/C++ Source or Header  |  1999-12-03  |  4.7 KB  |  145 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   Scan handler looking for HTML anchors.
  4.  
  5.   Scan handlers are plain functions (loadSeg()'ed): no standard C startup
  6.   code and no library calls permitted. We have to put string constants into
  7.   the code segment (DICE compiler: option -ms1).
  8.  
  9.   DICE-C:
  10.  
  11.   dcc html.c -// -l0 -md -ms2 -mRR -o golded:etc/scanner/html
  12.  
  13.   ------------------------------------------------------------------------------
  14. */
  15.  
  16. #include <exec/types.h>
  17.  
  18. #define UPPER(a) ((a) & 95)
  19.  
  20. ULONG
  21. ScanHandlerHTML(__D0 ULONG len, __A0 char **text, __A1 ULONG *line)
  22. {
  23.     const char *version = "$VER: HTML 1.3 (" __COMMODORE_DATE__ ")";
  24.  
  25.     // use string constant as result buffer (string constants go into the code section; remember: this program is compiled without startup code)
  26.  
  27.     UBYTE *buffer = "                                                       ";
  28.  
  29.     // minimum strings: <A NAME="X"> or <A HREF="X">
  30.  
  31.     if (len >= 12) {
  32.  
  33.         UBYTE *from, *start, *last;
  34.  
  35.         from = *text;
  36.         last = *text + len;
  37.  
  38.         while ((from + 11) < last) {
  39.  
  40.             // anchor detected ?
  41.  
  42.             if ((from[0] == '<') && (UPPER(from[1]) == 'A') && (from[2] == ' ')) {
  43.  
  44.                 // 1st try: look for <A HREF="..."> or <A NAME="...">
  45.  
  46.                 for (start = from + 3; start < last; ++start) {
  47.  
  48.                     if (UPPER(*start) == 'H') {
  49.  
  50.                         if (UPPER(start[1]) == 'R') {
  51.  
  52.                             if (UPPER(start[2]) == 'E') {
  53.  
  54.                                 if (UPPER(start[3]) == 'F') {
  55.  
  56.                                     for (start += 4; start < last; ++start) {
  57.  
  58.                                         // look for beginning of link string
  59.  
  60.                                         if (*start == 34) {
  61.  
  62.                                             UBYTE *result = buffer;
  63.  
  64.                                             *result++ = 'H';
  65.                                             *result++ = 'R';
  66.                                             *result++ = 'E';
  67.                                             *result++ = 'F';
  68.                                             *result++ = ' ';
  69.  
  70.                                             for (len = 5, ++start; start < last; ++len) {
  71.  
  72.                                                 if (len == 50)
  73.  
  74.                                                     break;
  75.  
  76.                                                 if (*start == 34) {
  77.  
  78.                                                     *text = buffer;
  79.  
  80.                                                     return(len);
  81.                                                 }
  82.                                                 else
  83.                                                     *result++ = *start++;
  84.                                             }
  85.                                         }
  86.                                     }
  87.                                 }
  88.                             }
  89.                         }
  90.                     }
  91.  
  92.                     if (UPPER(*start) == 'N') {
  93.  
  94.                         if (UPPER(start[1]) == 'A') {
  95.  
  96.                             if (UPPER(start[2]) == 'M') {
  97.  
  98.                                 if (UPPER(start[3]) == 'E') {
  99.  
  100.                                     for (start += 4; start < last; ++start) {
  101.  
  102.                                         // look for beginning of link string
  103.  
  104.                                         if (*start == 34) {
  105.  
  106.                                             UBYTE *result = buffer;
  107.  
  108.                                             *result++ = 'N';
  109.                                             *result++ = 'A';
  110.                                             *result++ = 'M';
  111.                                             *result++ = 'E';
  112.                                             *result++ = ' ';
  113.  
  114.                                             for (len = 5, ++start; start < last; ++len) {
  115.  
  116.                                                 if (len == 50)
  117.  
  118.                                                     break;
  119.  
  120.                                                 if (*start == 34) {
  121.  
  122.                                                     *text = buffer;
  123.  
  124.                                                     return(len);
  125.                                                 }
  126.                                                 else
  127.                                                     *result++ = *start++;
  128.                                             }
  129.                                         }
  130.                                     }
  131.                                 }
  132.                             }
  133.                         }
  134.                     }
  135.                 }
  136.             }
  137.  
  138.             ++from;
  139.         }
  140.     }
  141.  
  142.     return(FALSE);
  143. }
  144.  
  145.